﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CashCommon;

namespace Cash.Model
{
    public interface ICashEmployerGate
    {
        void RefreshFromDb(CashEmployer cashEmployer);
    }
    
    public class CashEmployer 
    {

        /// <summary>
        /// Статическое свойство класса для создания нового или получения текущего пользователя системы
        /// </summary>
        public static CashEmployer Inst
        {
            get
            {
                if (_cashEmployer == null)
                {
                    lock (_syncRoot)
                    {
                        _cashEmployer = new CashEmployer();
                        return _cashEmployer;
                    }
                }
                return _cashEmployer;
            }
        }

        public void Init(string login)
        {
            _cashEmployer.C_UID = login;
            _cashEmployer.RefreshFromDb(_cashEmployer);
        }

        #region Свойства пользователя

        public string LINK { get; set; }
        public string C_UID { get; set; }
        public string F_Division 
        {
            get 
            {
                return C_UID == ""? "-1000" : _fDivision; 
            }
            set
            {
                _fDivision = value;
            }
        }
        public string C_FIO {get; set;}
        public string SvDeptName { get; set; }

        #endregion

        private void RefreshFromDb(CashEmployer cashEmployer)
        {
            _gate.RefreshFromDb(this);
        }

        private string _fDivision;
        private static object _syncRoot = new Object();
        private static CashEmployer _cashEmployer;
        private static ICashEmployerGate _gate = Builder.CashEmployerGate;
    }
}
